package com.widget;














import com.friehome.app.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;


public class SAlertDialog extends Dialog{

	View.OnClickListener yes = null;
	View.OnClickListener no = null;
	View view;
	LayoutParams lp;
	public SAlertDialog(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
	}

	
	


	public LayoutParams getLp() {
		return lp;
	}





	public void setLp(LayoutParams lp) {
		this.lp = lp;
	}





	public View.OnClickListener getYes() {
		return yes;
	}





	public void setYes(View.OnClickListener yes) {
		this.yes = yes;
	}





	public View.OnClickListener getNo() {
		return no;
	}





	public void setNo(View.OnClickListener no) {
		this.no = no;
	}





	public View getView() {
		return view;
	}





	public void setView(View view) {
		this.view = view;
		try {
			view.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (no != null) {
						no.onClick(v);
					}
					
					SAlertDialog.this.cancel();
				}
			});
            view.findViewById(R.id.confirm_button).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (yes != null) {
						yes.onClick(v);
					}
					SAlertDialog.this.cancel();
				}
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}





	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		if(lp == null){
			setContentView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
		}else{
			setContentView(view,lp);

		}
		
		
		setCancelable(true);
//		Window window = this.getWindow();
//        window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
//        window.setWindowAnimations(R.style.dialogWindowAnim);  //添加动画
	}
	
	
}
